package repositories

import (
	"huanteng/web/global/application"
	"huanteng/web/models"
)
type UserRepository interface {
	Create(user *models.User)
    FindByName(name string)(user models.User,err error)
	FindByPhone(phone string)(user models.User,err error)
	//Select(query Query)(user models.User,found bool)
}

type userRepository struct {}
func NewUserRepository() UserRepository{
	return &userRepository{}
}

func (r *userRepository)Create(user *models.User)  {
	application.DB.Create(&user)
}

func (r *userRepository)FindByName(name string)(user models.User,err error){
	err=application.DB.Where("name=?",name).First(&user).Error
	return
}
func (r *userRepository)FindByPhone(phone string)(user models.User,err error){
	err=application.DB.Where("phone=?",phone).First(&user).Error
	return
}
